﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;

namespace Steamrunner
{
    class PhysicsManager : GameComponent
    {
        #region Variables
        Player player = null;
        LevelManager levelManager = null;

        float gravity = 0.3f;
        float jumpingSpeed = -0.3f;
        float jumpingLosingSpeed = 0.005f;
        float startJumpingY = 0.0f;
        float midJumpingY = 0.0f; // ??
        int stateAtStateChange = 0;

        Vector2 lastPosition = Vector2.Zero;
        bool stateJustChanged = false;
        bool okToJump = false;
        bool onTheRight = true;
        bool wallJumpToTheLeft = false;
        bool wallJumpToTheRight = false;
        bool drop = false;
        bool straightDrop = false;

        Timer starterTimer = null;
        Timer stunTimer = null;
        Timer fallingTimer = null;

        short currentTileLevel = (short)Enums.TileType.IRONFLOOR;

        //float walkingWoodSpeed = 0.0003f;
        //float walkingIronSpeed = 0.0004f;
        //float walkingCopperSpeed = 0.0005f;
        float joggingWoodSpeed = 0.005f;
        float joggingIronSpeed = 0.006f;
        float joggingCopperSpeed = 0.007f;
        float runningWoodSpeed = 0.03f;
        float runningIronSpeed = 0.05f;
        float runningCopperSpeed = 0.07f;

        //float walkingMaxSpeed = 0.015f;
        float joggingMaxSpeed = 0.3f;
        float runningWoodMaxSpeed = 0.2f;
        float runningIronMaxSpeed = 0.6f;
        float runningCopperMaxSpeed = 0.7f;
        #endregion

        #region Properties
        public float JoggingMaxSpeed
        {
            get { return joggingMaxSpeed; }
        }
        
        public Player Player
        {
            get { return player; }
        }

        public int StateAtStateChange
        {
            get { return stateAtStateChange; }
            set { stateAtStateChange = value; }
        }

        public bool StateJustChanged
        {
            get { return stateJustChanged; }
            set { stateJustChanged = value; }
        }

        public bool OkToJump
        {
            get { return okToJump; }
        }

        public bool OnTheRight
        {
            get { return onTheRight; }
        }

        public bool WallJumpToTheLeft
        {
            set { wallJumpToTheLeft = value; }
        }

        public bool WallJumpToTheRight
        {
            set { wallJumpToTheRight = value; }
        }

        public short CurrentTileLevel
        {
            get { return currentTileLevel; }
        }
        #endregion

        public PhysicsManager(Game game, Player player, LevelManager levelManager)
            : base(game)
        {
            this.player = player;
            this.levelManager = levelManager;
        }

        public override void Initialize()
        {
            starterTimer = new Timer(3000, 1000);
            stunTimer = new Timer(2500, 2500);
            fallingTimer = new Timer(10000, 10000);

            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            lastPosition = Player.Position;

            switch (player.CurrentState)
            {
                case (int)Enums.State.NOTSTARTED:
                    if (starterTimer.Update(gameTime))
                    {
                        player.CurrentState = (short)Enums.State.JOGGING;
                    }
                    break;
                case (int)Enums.State.WALKING:
                    Gravity(gameTime);
                    WalkingJoggingRunning(gameTime);
                    BumpIntoWall();
                    break;
                case (int)Enums.State.JOGGING:
                    stunTimer.Flush();
                    Gravity(gameTime);
                    WalkingJoggingRunning(gameTime);
                    BumpIntoWall();
                    break;
                case (int)Enums.State.RUNNING:
                    Gravity(gameTime);
                    WalkingJoggingRunning(gameTime);
                    BumpIntoWall();
                    break;
                case (int)Enums.State.SPRINTING:
                    Gravity(gameTime);
                    BumpIntoWall();
                    break;
                case (int)Enums.State.JUMPING:
                    Jumping(gameTime);
                    WallJumpBump();
                    //HeadBump();
                    break;
                case (int)Enums.State.FALLING:
                    if (!drop)
                    {
                        Falling(gameTime);
                    }
                    else
                    {
                        Drop(gameTime);
                    }
                    WallJumpBump();
                    break;
                case (int)Enums.State.SLIDING:
                    Gravity(gameTime);
                    Sliding(gameTime);
                    BumpIntoWall();
                    break;
                case (int)Enums.State.WALLJUMPING:
                    WallJump(gameTime);
                    break;
                case (int)Enums.State.FALLDAMAGE:
                    FallDamage(gameTime);
                    break;
                case (int)Enums.State.WALLBUMP:
                    WallBump(gameTime);
                    break;
                case (int)Enums.State.FINISHED:
                    break;
            }

            base.Update(gameTime);
        }

        void Gravity(GameTime gameTime)
        {
            player.Position = new Vector2(player.Position.X, player.Position.Y + (gravity * gameTime.ElapsedGameTime.Milliseconds));

            Vector2 bottomLeftOfPlayer = new Vector2(Player.Position.X, player.Position.Y + 32f);
            if (player.CurrentState == (short)Enums.State.SLIDING)
            {
                bottomLeftOfPlayer.X -= 32f;
            }

            Vector2 bottomRightOfPlayer = new Vector2(Player.Position.X + 32f, player.Position.Y + 32f);

            if (levelManager.GetTileTypeByScreenPos(bottomLeftOfPlayer) != (short)Enums.TileType.NOTHING)
            {
                currentTileLevel = levelManager.GetTileTypeByScreenPos(bottomLeftOfPlayer);
                player.Position = new Vector2(player.Position.X, levelManager.GetTopYForTile(bottomLeftOfPlayer) - 32f);
            }
            else if (levelManager.GetTileTypeByScreenPos(bottomRightOfPlayer) != (short)Enums.TileType.NOTHING)
            {
                currentTileLevel = levelManager.GetTileTypeByScreenPos(bottomLeftOfPlayer);
                player.Position = new Vector2(player.Position.X, levelManager.GetTopYForTile(bottomRightOfPlayer) - 32f);
            }
            else
            {
                stateAtStateChange = player.CurrentState;
                startJumpingY = player.Position.Y;
                player.CurrentState = (int)Enums.State.FALLING;
                drop = true;
            }
        }

        void WalkingJoggingRunning(GameTime gameTime)
        {
            if (currentTileLevel / 3 == 0)
            {
                /*if (player.Speed.X < walkingMaxSpeed)
                {
                    player.Speed = new Vector2(Math.Abs(player.Speed.X) + walkingWoodSpeed, 0f);
                }*/
                if (player.Speed.X < joggingMaxSpeed)
                {
                    player.Speed = new Vector2(Math.Abs(player.Speed.X) + joggingWoodSpeed, 0f);
                    player.CurrentState = (int)Enums.State.JOGGING;
                }
                else if (player.Speed.X < runningWoodMaxSpeed)
                {
                    player.Speed = new Vector2(Math.Abs(player.Speed.X) + runningWoodSpeed, 0f);
                    player.CurrentState = (int)Enums.State.RUNNING;
                }
                else
                {
                    player.Speed = new Vector2(runningWoodMaxSpeed, 0f);
                }
            }

            else if (currentTileLevel / 3 == 1)
            {
                /*if (player.Speed.X < walkingMaxSpeed)
                {
                    player.Speed = new Vector2(Math.Abs(player.Speed.X) + walkingIronSpeed, 0f);
                }*/
                if (player.Speed.X < joggingMaxSpeed)
                {
                    player.Speed = new Vector2(Math.Abs(player.Speed.X) + joggingIronSpeed, 0f);
                    player.CurrentState = (int)Enums.State.JOGGING;
                }
                else if (player.Speed.X < runningIronMaxSpeed)
                {
                    player.Speed = new Vector2(Math.Abs(player.Speed.X) + runningIronSpeed, 0f);
                    player.CurrentState = (int)Enums.State.RUNNING;
                }
                else
                {
                    player.Speed = new Vector2(runningIronMaxSpeed, 0f);
                }
            }

            else if (currentTileLevel / 3 == 2)
            {
                /*if (player.Speed.X < walkingMaxSpeed)
                {
                    player.Speed = new Vector2(Math.Abs(player.Speed.X) + walkingCopperSpeed, 0f);
                }*/
                if (player.Speed.X < joggingMaxSpeed)
                {
                    player.Speed = new Vector2(Math.Abs(player.Speed.X) + joggingCopperSpeed, 0f);
                    player.CurrentState = (int)Enums.State.JOGGING;
                }
                else if (player.Speed.X < runningCopperMaxSpeed)
                {
                    player.Speed = new Vector2(Math.Abs(player.Speed.X) + runningCopperSpeed, 0f);
                    player.CurrentState = (int)Enums.State.RUNNING;
                }
                else
                {
                    player.Speed = new Vector2(runningCopperMaxSpeed, 0f);
                }
            }

            player.Position += player.Speed * gameTime.ElapsedGameTime.Milliseconds;
        }

        void Jumping(GameTime gameTime)
        {
            if (onTheRight)
            {
                if (stateJustChanged)
                {
                    player.Speed = new Vector2(Math.Abs(player.Speed.X), jumpingSpeed);
                    startJumpingY = player.Position.Y;
                    okToJump = false;

                    player.MusicManager.PlaySound("jumping");

                    stateJustChanged = false;
                }
                else if (player.Speed.Y < 0)
                {
                    player.Speed = new Vector2(player.Speed.X, player.Speed.Y + jumpingLosingSpeed);
                }
                else
                {
                    midJumpingY = player.Position.Y;
                    player.CurrentState = (short)Enums.State.FALLING;
                }
            }
            else
            {
                if (stateJustChanged)
                {
                    player.Speed = new Vector2(-Math.Abs(player.Speed.X), jumpingSpeed);
                    startJumpingY = player.Position.Y;

                    player.MusicManager.PlaySound("jumping");

                    stateJustChanged = false;
                }
                else if (player.Speed.Y < 0)
                {
                    player.Speed = new Vector2(player.Speed.X, player.Speed.Y + jumpingLosingSpeed);
                }
                else
                {
                    midJumpingY = player.Position.Y;
                    player.CurrentState = (short)Enums.State.FALLING;
                }
            }

            player.Position += player.Speed * gameTime.ElapsedGameTime.Milliseconds;
        }

        void Falling(GameTime gameTime)
        {
            if (player.Speed.Y < gravity)
            {
                player.Speed = new Vector2(player.Speed.X, player.Speed.Y + jumpingLosingSpeed);
            }
            else
            {
                player.Speed = new Vector2(player.Speed.X, gravity);
            }

            player.Position += player.Speed * gameTime.ElapsedGameTime.Milliseconds;

            Vector2 bottomLeftOfPlayer = new Vector2(Player.Position.X + 10f, player.Position.Y + 32f);
            Vector2 bottomRightOfPlayer = new Vector2(Player.Position.X + 22f, player.Position.Y + 32f);

            if (levelManager.GetTileTypeByScreenPos(bottomLeftOfPlayer) != (short)Enums.TileType.NOTHING && levelManager.GetTileTypeByScreenPos(bottomRightOfPlayer) != (short)Enums.TileType.NOTHING || fallingTimer.Update(gameTime))
            {
                fallingTimer.Flush();
                onTheRight = true;
                player.MusicManager.PlaySound("landing");
                currentTileLevel = levelManager.GetTileTypeByScreenPos(bottomLeftOfPlayer);
                player.Position = new Vector2(player.Position.X, levelManager.GetTopYForTile(bottomLeftOfPlayer) - 32f);
                if (stateAtStateChange == (int)Enums.State.FALLING)
                {
                    stateAtStateChange = (int)Enums.State.JOGGING;
                }
                player.CurrentState = stateAtStateChange;
                if (currentTileLevel / 3 == 0)
                {
                    if (player.CurrentState == (int)Enums.State.RUNNING && player.Speed.X > runningWoodMaxSpeed)
                    {
                        player.Speed = new Vector2(runningWoodMaxSpeed, 0f);
                    }
                }
                else if (currentTileLevel / 3 == 1)
                {
                    if (player.CurrentState == (int)Enums.State.RUNNING && player.Speed.X > runningIronMaxSpeed)
                    {
                        player.Speed = new Vector2(runningIronMaxSpeed, 0f);
                    }
                }
            }
            /*else if (levelManager.GetTileTypeByScreenPos(bottomRightOfPlayer) != (short)Enums.TileType.NOTHING)
            {
                onTheRight = true;
                player.MusicManager.PlaySound("landing");
                currentTileLevel = levelManager.GetTileTypeByScreenPos(bottomRightOfPlayer);
                player.Position = new Vector2(player.Position.X, levelManager.GetTopYForTile(bottomRightOfPlayer) - 32f);
                player.CurrentState = stateAtStateChange;
            }*/
        }

        void Sliding(GameTime gameTime)
        {
            if (currentTileLevel / 3 == 0)
            {
                /*if (player.Speed.X < walkingMaxSpeed)
                {
                    player.Speed = new Vector2(player.Speed.X + walkingWoodSpeed, 0f);
                }*/
                if (player.Speed.X < joggingMaxSpeed)
                {
                    player.Speed = new Vector2(player.Speed.X + joggingWoodSpeed, 0f);
                    stateAtStateChange = (int)Enums.State.JOGGING;
                }
                else if (player.Speed.X < runningWoodMaxSpeed)
                {
                    player.Speed = new Vector2(player.Speed.X + runningWoodSpeed, 0f);
                    stateAtStateChange = (int)Enums.State.RUNNING;
                }
                else
                {
                    player.Speed = new Vector2(runningWoodMaxSpeed, 0f);
                }
            }

            else if (currentTileLevel / 3 == 1)
            {
                /*if (player.Speed.X < walkingMaxSpeed)
                {
                    player.Speed = new Vector2(player.Speed.X + walkingIronSpeed, 0f);
                }*/
                if (player.Speed.X < joggingMaxSpeed)
                {
                    player.Speed = new Vector2(player.Speed.X + joggingIronSpeed, 0f);
                    stateAtStateChange = (int)Enums.State.JOGGING;
                }
                else if (player.Speed.X < runningIronMaxSpeed)
                {
                    player.Speed = new Vector2(player.Speed.X + runningIronSpeed, 0f);
                    stateAtStateChange = (int)Enums.State.RUNNING;
                }
                else
                {
                    player.Speed = new Vector2(runningIronMaxSpeed, 0f);
                }
            }

            else if (currentTileLevel / 3 == 2)
            {
                /*if (player.Speed.X < walkingMaxSpeed)
                {
                    player.Speed = new Vector2(player.Speed.X + walkingCopperSpeed, 0f);
                }*/
                if (player.Speed.X < joggingMaxSpeed)
                {
                    player.Speed = new Vector2(player.Speed.X + joggingCopperSpeed, 0f);
                    stateAtStateChange = (int)Enums.State.JOGGING;
                }
                else if (player.Speed.X < runningCopperMaxSpeed)
                {
                    player.Speed = new Vector2(player.Speed.X + runningCopperSpeed, 0f);
                    stateAtStateChange = (int)Enums.State.RUNNING;
                }
                else
                {
                    player.Speed = new Vector2(runningCopperMaxSpeed, 0f);
                }
            }

            player.Position += player.Speed * gameTime.ElapsedGameTime.Milliseconds;
        }

        void BumpIntoWall()
        {
            Vector2 topRightOfPlayer = new Vector2(Player.Position.X + 32f, player.Position.Y - 32f);
            Vector2 bottomRightOfPlayer = new Vector2(Player.Position.X + 32f, player.Position.Y + 25f);
            if (player.CurrentState == (short)Enums.State.SLIDING)
            {
                topRightOfPlayer.Y = player.Position.Y;
            }
            
            if (levelManager.GetTileTypeByScreenPos(topRightOfPlayer) != (short)Enums.TileType.NOTHING)
            {
                player.Position = new Vector2(levelManager.GetTopLeftXForTile(topRightOfPlayer) - levelManager.TileSize.X - 10f, player.Position.Y);
                player.CurrentState = (int)Enums.State.WALLBUMP;
            }
            else if (levelManager.GetTileTypeByScreenPos(bottomRightOfPlayer) != (short)Enums.TileType.NOTHING)
            {
                player.Position = new Vector2(levelManager.GetTopLeftXForTile(bottomRightOfPlayer) - levelManager.TileSize.X - 10f, player.Position.Y);
                player.CurrentState = (int)Enums.State.WALLBUMP;
            }
        }

        void WallBump(GameTime gameTime)
        {
            // Changing speed so it is almost zero
            if (currentTileLevel / 3 == 0)
            {
                player.Speed = new Vector2(joggingWoodSpeed * 5, 0f);
                stateAtStateChange = (int)Enums.State.JOGGING;
                okToJump = true;
            }
            else if (currentTileLevel / 3 == 1)
            {
                player.Speed = new Vector2(joggingWoodSpeed * 5, 0f);
                stateAtStateChange = (int)Enums.State.JOGGING;
                okToJump = true;
            }
            else if (currentTileLevel / 3 == 2)
            {
                player.Speed = new Vector2(joggingWoodSpeed * 5, 0f);
                stateAtStateChange = (int)Enums.State.JOGGING;
                okToJump = true;
            }

            if (stunTimer.Update(gameTime))
            {
                if (currentTileLevel / 3 == 0)
                {
                    player.Speed = new Vector2(joggingWoodSpeed, 0f);
                    player.CurrentState = (int)Enums.State.JOGGING;
                }
                else if (currentTileLevel / 3 == 1)
                {
                    player.Speed = new Vector2(joggingWoodSpeed, 0f);
                    player.CurrentState = (int)Enums.State.JOGGING;
                }
                else if (currentTileLevel / 3 == 2)
                {
                    player.Speed = new Vector2(joggingWoodSpeed, 0f);
                    player.CurrentState = (int)Enums.State.JOGGING;
                }
            }
        }

        void FallDamage(GameTime gameTime)
        {
            // Changing speed so it is almost zero
            if (currentTileLevel / 3 == 0)
            {
                player.Speed = new Vector2(joggingWoodSpeed, 0f);
                player.CurrentState = (int)Enums.State.JOGGING;
            }
            else if (currentTileLevel / 3 == 1)
            {
                player.Speed = new Vector2(joggingIronSpeed, 0f);
                player.CurrentState = (int)Enums.State.JOGGING;
            }
            else if (currentTileLevel / 3 == 2)
            {
                player.Speed = new Vector2(joggingCopperSpeed, 0f);
                player.CurrentState = (int)Enums.State.JOGGING;
            }
        }

        void WallJumpBump()
        {
            // med onTheRight checka vägar till höger eller vänster om karaktären
            if (onTheRight)
            {
                Vector2 topRightOfPlayer = new Vector2(Player.Position.X + 32f, player.Position.Y - 25f);
                Vector2 bottomRightOfPlayer = new Vector2(Player.Position.X + 32f, player.Position.Y + 25f);

                if (levelManager.GetTileTypeByScreenPos(topRightOfPlayer) != (short)Enums.TileType.NOTHING && levelManager.GetTileTypeByScreenPos(bottomRightOfPlayer) != (short)Enums.TileType.NOTHING)
                {
                    player.Position = new Vector2(levelManager.GetTopLeftXForTile(topRightOfPlayer) - levelManager.TileSize.X, player.Position.Y);
                    player.MusicManager.PlaySound("wallhugging");
                    player.CurrentState = (int)Enums.State.WALLJUMPING;
                }
            }
            else
            {
                Vector2 topLeftOfPlayer = new Vector2(Player.Position.X - 32f, player.Position.Y - 25f);
                Vector2 bottomLeftOfPlayer = new Vector2(Player.Position.X - 32f, player.Position.Y + 25f);

                if (levelManager.GetTileTypeByScreenPos(topLeftOfPlayer) != (short)Enums.TileType.NOTHING && levelManager.GetTileTypeByScreenPos(bottomLeftOfPlayer) != (short)Enums.TileType.NOTHING)
                {
                    player.Position = new Vector2(levelManager.GetTopLeftXForTile(topLeftOfPlayer) + (levelManager.TileSize.X * 2), player.Position.Y);
                    player.MusicManager.PlaySound("wallhugging");
                    player.CurrentState = (int)Enums.State.WALLJUMPING;
                }
            }
        }

        void WallJump(GameTime gameTime)
        {
            if (wallJumpToTheLeft)
            {
                stateJustChanged = true;
                player.CurrentState = (int)Enums.State.JUMPING;
                wallJumpToTheLeft = false;
                onTheRight = false;
            }
            else if (wallJumpToTheRight)
            {
                stateJustChanged = true;
                player.CurrentState = (int)Enums.State.JUMPING;
                wallJumpToTheRight = false;
                onTheRight = true;
            }
            else
            {
                player.Speed = new Vector2(Math.Abs(player.Speed.X), 0f);
                player.Position = new Vector2(player.Position.X, player.Position.Y + ((gravity * 0.5f) * gameTime.ElapsedGameTime.Milliseconds));
                if (onTheRight)
                {
                    Vector2 topRightOfPlayer = new Vector2(Player.Position.X + 32f, player.Position.Y - 32f);
                    if (levelManager.GetTileTypeByScreenPos(topRightOfPlayer) == (short)Enums.TileType.NOTHING)
                    {
                        startJumpingY = player.Position.Y;
                        drop = true;
                        straightDrop = true;
                        player.CurrentState = (int)Enums.State.FALLING;
                    }
                }
                else
                {
                    Vector2 topLeftOfPlayer = new Vector2(Player.Position.X - 64f, player.Position.Y - 32f);
                    if (levelManager.GetTileTypeByScreenPos(topLeftOfPlayer) == (short)Enums.TileType.NOTHING)
                    {
                        startJumpingY = player.Position.Y;
                        drop = true;
                        straightDrop = true;
                        player.CurrentState = (int)Enums.State.FALLING;
                    }
                }
            }
        }

        void Drop(GameTime gameTime)
        {
            if (player.Speed.Y < gravity)
            {
                player.Speed = new Vector2(player.Speed.X, player.Speed.Y + jumpingLosingSpeed);
            }
            else
            {
                player.Speed = new Vector2(player.Speed.X, gravity);
            }

            if (!straightDrop)
            {
                player.Position += new Vector2(player.Speed.X * 0.8f, player.Speed.Y * 5) * gameTime.ElapsedGameTime.Milliseconds;
            }
            else
            {
                player.Position += new Vector2(0f, player.Speed.Y) * gameTime.ElapsedGameTime.Milliseconds;
            }

            Vector2 bottomLeftOfPlayer = new Vector2(Player.Position.X + 10f, player.Position.Y + 32f);
            Vector2 bottomRightOfPlayer = new Vector2(Player.Position.X + 22f, player.Position.Y + 32f);

            if (levelManager.GetTileTypeByScreenPos(bottomLeftOfPlayer) != (short)Enums.TileType.NOTHING && levelManager.GetTileTypeByScreenPos(bottomRightOfPlayer) != (short)Enums.TileType.NOTHING || fallingTimer.Update(gameTime))
            {
                fallingTimer.Flush();
                onTheRight = true;
                drop = false;
                straightDrop = false;
                player.MusicManager.PlaySound("landing");
                currentTileLevel = levelManager.GetTileTypeByScreenPos(bottomLeftOfPlayer);
                player.Position = new Vector2(player.Position.X, levelManager.GetTopYForTile(bottomLeftOfPlayer) - 32f);
                if (stateAtStateChange == (int)Enums.State.FALLING)
                {
                    stateAtStateChange = (int)Enums.State.JOGGING;
                }
                player.CurrentState = stateAtStateChange;
                if (currentTileLevel / 3 == 0)
                {
                    if (player.CurrentState == (int)Enums.State.RUNNING && player.Speed.X > runningWoodMaxSpeed)
                    {
                        player.Speed = new Vector2(runningWoodMaxSpeed, 0f);
                    }
                }
                else if (currentTileLevel / 3 == 1)
                {
                    if (player.CurrentState == (int)Enums.State.RUNNING && player.Speed.X > runningIronMaxSpeed)
                    {
                        player.Speed = new Vector2(runningIronMaxSpeed, 0f);
                    }
                }
            }
            /*else if (levelManager.GetTileTypeByScreenPos(bottomRightOfPlayer) != (short)Enums.TileType.NOTHING)
            {
                onTheRight = true;
                drop = false;
                straightDrop = false;
                player.MusicManager.PlaySound("landing");
                currentTileLevel = levelManager.GetTileTypeByScreenPos(bottomRightOfPlayer);
                player.Position = new Vector2(player.Position.X, levelManager.GetTopYForTile(bottomRightOfPlayer) - 32f);
                player.CurrentState = stateAtStateChange;
            }*/
        }

        public bool EndSliding()
        {
            Vector2 topRightOfPlayer = new Vector2(Player.Position.X + 32f, player.Position.Y - 32f);
            Vector2 bottomRightOfPlayer = new Vector2(Player.Position.X + 32f, player.Position.Y + 25f);

            if (levelManager.GetTileTypeByScreenPos(topRightOfPlayer) != (short)Enums.TileType.NOTHING || levelManager.GetTileTypeByScreenPos(bottomRightOfPlayer) != (short)Enums.TileType.NOTHING)
            {
                return false;
            }
            player.MusicManager.StopRocket();
            return true;
        }

        void HeadBump()
        {
            Vector2 topLeftOfPlayer = new Vector2(Player.Position.X, player.Position.Y - 32f);
            Vector2 topRightOfPlayer = new Vector2(Player.Position.X + 32f, player.Position.Y - 32f);

            if (levelManager.GetTileTypeByScreenPos(topLeftOfPlayer) != (short)Enums.TileType.NOTHING && levelManager.GetTileTypeByScreenPos(topRightOfPlayer) != (short)Enums.TileType.NOTHING)
            {
                player.CurrentState = (int)Enums.State.FALLING;
            }
        }
    }
}
